/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.tfg.bean;

import edu.tfg.dao.FeedDAO;
import edu.tfg.model.Feed;
import java.util.List;
import java.util.Objects;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Juarez
 */
@ManagedBean
@SessionScoped
public class FeedBean {
    
    private Feed feed = new Feed ();
    private FeedDAO feedDAO = new FeedDAO();
    private List listaFeeds;

    public List getListaFeeds() {
        return listaFeeds;
    }

    public void setListaFeeds(List listaFeeds) {
        this.listaFeeds = listaFeeds;
    }
    
    public FeedBean() {
    }

    public Feed getFeed() {
        return feed;
    }

    public void setFeed(Feed feed) {
        this.feed = feed;
    }

    public FeedDAO getFeedDAO() {
        return feedDAO;
    }

    public void setFeedDAO(FeedDAO feedDAO) {
        this.feedDAO = feedDAO;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 41 * hash + Objects.hashCode(this.feed);
        hash = 41 * hash + Objects.hashCode(this.feedDAO);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FeedBean other = (FeedBean) obj;
        if (!Objects.equals(this.feed, other.feed)) {
            return false;
        }
        if (!Objects.equals(this.feedDAO, other.feedDAO)) {
            return false;
        }
        return true;
    }
    
     public String adicionaFeed(){
        feedDAO.salvar(feed);
        return "index";
    }

     public String removeFeed(){
        feedDAO.removeFeed(feed);
        return "sucesso";
     }
     
      public List listarFeeds(){
         listaFeeds = feedDAO.listarFeeds();
         return listaFeeds;
     }
     public String alterarFeed(){
            feedDAO.alterarFeed(feed);
         return "index";
     }
     
     public String pesquisarFeed(){
         feedDAO.pesquisarFeed(null);
         return "index";
     }
    
    
    
    
}
